﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Security.Cryptography;
using TracNghiemTinHocDaiCuong.BIZ;
using TracNghiemTinHocDaiCuong.ThucThe;
using TracNghiemTinHocDaiCuong.Common;

namespace TracNghiemTinHocDaiCuong
{
    public partial class DangNhap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            MD5 md5Hash = MD5.Create();
            string hash = MethodHelper.LayBangBamMD5(md5Hash, txtMatKhau.Text);
            int nguoiDungMoi = NguoiDungBIZ.TimKiem(txtTenTaiKhoan.Text, hash);
            if (nguoiDungMoi != -1)
            {
                NguoiDung nd = NguoiDungBIZ.TimKiemTheoId(nguoiDungMoi);
                if (nd.LaQuanTri == true)
                {
                    Session["idQuanTri"] = nguoiDungMoi;
                    Response.Redirect(string.Format("HomeBackend.aspx"));
                }
                else
                {
                    Session["idNguoiDung"] = nguoiDungMoi;
                    Session["NguoiDung"] = "True";
                    Response.Redirect(string.Format("Home.aspx"));
                }
            }
            else
                lblThongBao.Text = "Tên đăng nhập hoặc mật khẩu không đúng";
        }        
    }
}